<%-- 
    Document   : MUserDetail
    Created on : 9 ??.?. 2554, 15:27:39
    Author     : SUNTIPARB
--%>
<%@ include file="/WEB-INF/jspf/taglib.jspf" %>
<%@page import="java.util.ResourceBundle"%>
<%-- Form Function --%>
<script type="text/javascript">
<%ResourceBundle resource = ResourceBundle.getBundle("Constant_en");%>
var dataStatus =  <%= resource.getString("cureplan.status") %>;
var strSelectDefault = "<%= resource.getString("project.select.default") %>";
    // pre-submit callback
    function showRequest(formData, jqForm, options) {
//        // formData is an array; here we use $.param to convert it to a string to display it
//        // but the form plugin does this for you automatically when it submits the data
//        var queryString = $.param(formData);
//
//        // jqForm is a jQuery object encapsulating the form element.  To access the
//        // DOM element for the form do this:
//        // var formElement = jqForm[0];
//
//        alert('About to submit: \n\n' + queryString);
//
//        // here we could return false to prevent the form from being submitted;
//        // returning anything other than false will allow the form submit to continue
//        return true;
    }

    // post-submit callback
    function showResponse(responseText, statusText, xhr, $form)  {
        ContentAjaxRequest('SRV/MUserDetail?rnd='+Math.random(), 'section #container');
    }
    $(document).ready(function() {
        populateSelect($('#ddlStatus').get(0), dataStatus, strSelectDefault);
        $("#formMUser").find("input, select, button").uniform();
        $("#formSearch").find("input, select, button").uniform();
        $("#btnBack").click(function(){
//            ContentAjaxRequest('SRV/MDoctorList', 'section #container');
        });
        $("#btnCurePlanBack").click(function(){
            ContentAjaxRequest('SRV/CureplanDetail?fromPage=<%=  request.getAttribute("fromPage")%>&cureServiceId=<%=  request.getAttribute("cureServiceId")%>&curePlanId=<%=  request.getAttribute("curePlanId")%>', 'section #container');
        });

        //Bind form submit
        var options = {
            url: '<%=request.getContextPath()%>/SRV/MUserDetail/formMUser_Submit',
            type: 'POST',
            dataType:  'html',
            beforeSubmit:  showRequest,  // pre-submit callback
            success:       showResponse  // post-submit callback

            // other available options:
            //url:       url         // override for form's 'action' attribute
            //type:      type        // 'get' or 'post', override for form's 'method' attribute
            //dataType:  null        // 'xml', 'script', or 'json' (expected server response type)
            //clearForm: true        // clear all form fields after successful submit
            //resetForm: true        // reset the form after successful submit

            // $.ajax options can be used here too, for example:
            //timeout:   3000
        };
        $("#formMUser").validate({
            rules: {
                txtUsername : "required",
                txtName : "required",
                txtSurname : "required"
            },
            messages: {
                txtCode : "Please enter UserName",
                txtName : "Please enter Name",
                txtSurname : "Please enter Surname"
            },
            submitHandler: function(form) {
                $(form).ajaxSubmit(options);
            }
        });
        
        $("#btnReset").click(function(){
            $("#formSearch").get(0).reset();
            populateSelect($('#ddlStatus').get(0), dataStatus, strSelectDefault);
            return false
        });

        $("#formSearch").validate({
            submitHandler: function(form) {
                gridReload();
            }
        });
    });


</script>
<%-- End Form Function --%>
<%-- jQGrid Init  --%>
<!--<script type="text/javascript">
jQuery.extend($.fn.fmatter , {
    imageButtonFormatter : function imageButtonFormatter(cellvalue, options, rowdata) {
    return "<a href=\"javascript:ContentAjaxRequest('SRV/CureplanDetail?curePlanId=" + rowdata[0] + "&fromPage=SRV_CureplanList', 'section #container')\" ><img src='<%=request.getContextPath()%>/images/view_icon.gif' /></a> ";
}
});
jQuery.extend($.fn.fmatter.imageButtonFormatter , {
    unformat : function(cellvalue, options) {
    return cellvalue;
}
});

</script>-->
<script type="text/javascript">

   $(function() {
        var UserId = jQuery("#UserId").val();
        $("#grid").jqGrid({
            url:'<%=request.getContextPath()%>/SRV/MUserDetail/grd_search?UserId='+UserId,
            datatype: 'json',
            mtype: 'POST',
            colNames:['Id','Service Name', 'Price', 'Currency', 'Doctor Name', 'Hospital','Status'],
            colModel:[
                {name:'ID',index:'id', width:40},
                {name:'serviceName',index:'srvCureservice.name', width:150},
                {name:'price',index:'srvCureservice.price', width:80},
                {name:'currency',index:'srvCureservice.currency', width:80},
                {name:'doctorName',index:'srvCureservice.mDoctor.name', width:140},
                {name:'hospitalName',index:'srvCureservice.mHospital.name', width:120},
                {name:'Status',index:'status', width:65}
//                {name:'Detail',index:'Detail', align:'center', width:45, sortable:false,formatter:'imageButtonFormatter'}
       ],
            postData: {
            },
            rowNum:20,
            rowList:[20,40,60],
            height: 200,
            width: 650,
            rownumbers: true,
            pager: '#pager',
            sortname: 'id',
            viewrecords: true,
            sortorder: "asc",
            caption:"Log Services",
            emptyrecords: "<%= resource.getString("EmptyRecordGrid") %>",
            loadonce: false,
            loadComplete: function() {
//                alert("Complete");
            },
            jsonReader : {
                root: "rows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems: true, //if 'false' will chage json reader format to 'name' require
                //cell: "cell",
                id: "0" //id: "id"
            }
        });
    }
);
    //jQuery("#grid").setGridWidth(800, true)
</script>

<%-- End jQGrid Init --%>

<%-- jQGrid Search Function --%>
<script type="text/javascript">

    function gridReload(){
        var txtKeyword = jQuery("#txtKeyword").val();
        var txtPrice = jQuery("#txtPrice").val();
        var ddlStatus = jQuery("#ddlStatus").val();
        var UserId = jQuery("#UserId").val();
        jQuery("#grid").jqGrid('setGridParam'
        ,{url:"<%=request.getContextPath()%>/SRV/MUserDetail/grd_search"
                +"?txtKeyword="+txtKeyword
                +"&txtPrice="+txtPrice
                +"&ddlStatus="+ddlStatus
                +"&UserId="+UserId
            ,page:1}).trigger("reloadGrid");
    }

</script>
<%-- End jQGrid Search Function --%>
<!-- insert content here -->
<h3>User Detail</h3>
<div class="grid_4">
    <div class="box1">
        <div class="indent-box1">
            <div class="wrapper">
                <img src="<%=request.getContextPath()%>/images/user/0.png" alt="" class="p1" />
                <form id="formMUser" class="form" method="">
                <!-- Query String -->
                    <input type="hidden" id="UserId" name="UserId" value="<%=  request.getAttribute("UserId")%>" />
                <!-- End Query String -->
                    <table>
                        <tr>
                            <td><em>Username</em></td>
                        </tr>
                        <tr>
                            <td>
                                <div class="p1" id="txtUsername_wrapper">
                                    <input type="text" name="txtUsername" id="txtUsername" class="width-100" value="<%=  request.getAttribute("txtUsername")%>" <%=  request.getAttribute("disabledInput")%> />
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><em>Name</em></td>
                        </tr>
                        <tr>
                            <td>
                                <div class="p1" id="txtName_wrapper">
                                    <input type="text" name="txtName" id="txtName" class="width-100" value="<%=  request.getAttribute("txtName")%>" <%=  request.getAttribute("disabledInput")%> />
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><em>Surname</em></td>
                        </tr>
                        <tr>
                            <td>
                                <div class="p1" id="txtSurname_wrapper">
                                    <input type="text" name="txtSurname" id="txtSurname" class="width-100" value="<%=  request.getAttribute("txtSurname")%>" <%=  request.getAttribute("disabledInput")%> />
                                </div>
                            </td>
                        </tr>
                        <c:choose>
                            <c:when test="${disabledInput=='Disabled'}">
                                <tr>
                                    <td class="control">
                                        <input type="button" name="btnCurePlanBack" id="btnCurePlanBack" value="Back" />
                                    </td>
                                </tr>
                            </c:when>
                            <c:otherwise>
                                <tr>
                                    <td><em>Permission</em></td>
                                </tr>
                                <tr>
                                    <td>
                                        <div class="p1" id="chcPerm_wrapper">
                                        <input type="checkbox" name="chcPerm_File" id="chcPerm_File" class="" value="true" <%=  request.getAttribute("chcPerm_File")%> />View File
                                        <input type="checkbox" name="chcPerm_Log" id="chcPerm_Log" class="" value="true" <%=  request.getAttribute("chcPerm_Log")%> />View Log
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="control">
                                        <input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" />
                                        <input type="button" name="btnBack" id="btnBack" value="Back" />
                                    </td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="grid_1">

</div>
<div class="grid_12">
    <c:if test="${chcPerm_File=='Checked'}">
        <div id="showFile">
            <div class="box1 p1">
                <div class="indent-box1">
                    <div class="wrapper">
                        <h5>User File</h5>
                        <table class="bgTable p1">
                            <thead>
                                <th>No.</th>
                                <th>Name</th>
                            </thead>
                            <tr align="center">
                                <td class="bgCellNormal" style="text-align:center">
                                    1
                                </td>
                                <td class="bgCellInput" style="text-align:center">
                                    <a href="<%=request.getContextPath()%>/images/file/x-ray.jpg" target="_blank">X-Ray Lung Film</a>
                                </td>
                            </tr>
                            <tr align="center">
                                <td class="bgCellNormal" style="text-align:center">
                                    2
                                </td>
                                <td class="bgCellInput" style="text-align:center">
                                    <a href="<%=request.getContextPath()%>/images/file/allergic.pdf" target="_blank">Allergic Record</a>
                                </td>
                            </tr>
                        </table>
                        <div class="p1" id="uplAttachFile_wrapper">
                            <div class="uploader" id="pnlAttachFile">
                                <input class="file" type="file" id="uplAttachFile" name="uplAttachFile" style="opacity: 0;" >
                                <span class="filename">No file selected</span>
                                <span class="action">Choose File</span>
                                <small>
                                    file type: .doc, .docx, .pdf | file size: 10 MB
                                </small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </c:if>
    <c:if test="${chcPerm_Log=='Checked'}">
        <div id="showLog">
            <div class="box1 p1">
                <div class="indent-box1">
                    <div class="wrapper">
                        <h5>User Log</h5>
                        <form id="formSearch" class="form" action="" method="">
                            <fieldset>
                                <legend>Search Service Log</legend>
                                <table>
                                    <tr>
                                        <td>Keyword</td>
                                        <td>
                                            <input type="text" name="txtKeyword" id="txtKeyword" class="" value="" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Service Price</td>
                                        <td>
                                            <input type="text" name="txtPrice" id="txtPrice" class="" value="" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Status</td>
                                        <td>
                                            <select id="ddlStatus" name="ddlStatus" class=""></select>
                                        </td>
                                    </tr>
                                    <tr >
                                        <td></td>
                                        <td class="control">
                                            <input type="reset" name="btnReset" id="btnReset" value="Reset" />
                                            <input type="submit" name="btnSearchSubmit" id="btnSearchSubmit" value="Search" />
                                        </td>
                                    </tr>
                                </table>
                            </fieldset>
                        </form>
                        <br />
                        <div id="jqgrid">
                            <table id="grid"></table>
                            <div id="pager"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </c:if>
</div>
